package com.xy.server.database;

import com.xy.server.entity.MosaicTemplate;
import com.xy.server.entity.Profile;
import com.xy.server.util.ServerUtil;

import java.io.File;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class FaceDBService extends SqliteDBService {


//    public static void func2() throws SQLException {
//        Statement statement = connection.createStatement();
//        Statement statement1 = connection.createStatement();
//        statement.setQueryTimeout(30); // set timeout to 30 sec.
//        // 执行查询语句
//        ResultSet rs = statement.executeQuery("select * from profile");
//        while (rs.next()) {
//            String col1 = rs.getString("username");
//            String col2 = rs.getString("password");
//            System.out.println("col1 = " + col1 + "  col2 = " + col2);
//
//            //System.out.println(location);
//            // 执行插入语句操作
//            //statement1.executeUpdate("insert into profile(username,password) values('gan2','sheng2')");
//            // 执行更新语句
////            statement1.executeUpdate("update table_name2 set 字段名1=" +  字段值1 + " where 字段名2='" +  字段值2 + "'");
//        }
//    }
//
//    public static int getDicValueByName(String name) throws SQLException {
//        Statement statement = connection.createStatement();
//
//        statement.setQueryTimeout(30);
//        ResultSet rs = statement.executeQuery("select value from dictionary where name ='" + name +"'");
//        while (rs.next()) {
//            int value = rs.getInt("value");
//
//            return value;
//        }
//
//        return 0;
//    }
//
//    public static String getDicStringByName(String name) throws SQLException {
//        Statement statement = connection.createStatement();
//
//        statement.setQueryTimeout(30);
//        ResultSet rs = statement.executeQuery("select value from dictionary where name ='" + name +"'");
//        while (rs.next()) {
//            String value = rs.getString("value");
//
//            return value;
//        }
//
//        return null;
//    }
//
//
//    public static void increaseDicValue(String name) throws SQLException {
//        Statement statement = connection.createStatement();
//        statement.setQueryTimeout(30);
//
//        statement.executeUpdate("update dictionary set value=value+1 where name='" +  name + "'");
//
//    }
//
//    public static void updateDicValue(String name,int value) throws SQLException {
//        Statement statement = connection.createStatement();
//        statement.setQueryTimeout(30);
//
//        statement.executeUpdate("update dictionary set value="+value+" where name='" +  name + "'");
//
//    }
//
//
//
//    public static void addProfile(String origin_file_name,String profile_file_name,String emotion,
//                                  int red_count,int green_count , int blue_count , int pixel_count) throws SQLException {
//        Statement statement = connection.createStatement();
//        statement.setQueryTimeout(30);
//
//        statement.executeUpdate("insert into capture_profile(origin_file_name,profile_file_name,emotion,red_count,green_count,blue_count,pixel_count,create_time) " +
//                "values('" + origin_file_name + "','" + profile_file_name + "','" + emotion + "',"+red_count+","+green_count+","+blue_count+","+pixel_count+"," + System.currentTimeMillis() + ")"
//        );
//
//    }
//
//    public static void clearMosaicTemplate() throws SQLException {
//        Statement statement = connection.createStatement();
//        statement.setQueryTimeout(30);
//
//        statement.executeUpdate("delete from mosaic_template");
//    }
//
//    public static void addMosaicTemplate(int x, int y, int width,int height,
//                                  int red_count,int green_count , int blue_count , int pixel_count) throws SQLException {
//        Statement statement = connection.createStatement();
//        statement.setQueryTimeout(30);
//
//        statement.executeUpdate(
//                "insert into mosaic_template(x,y,width,height,red_count,green_count,blue_count,pixel_count,create_time) " +
//                "values(" + x + "," + y + "," + width + ","+ height +","+red_count+","+green_count+","+blue_count+","+pixel_count+"," + System.currentTimeMillis() + ")"
//        );
//
//    }
//
//    public static List<Profile> getProfileList(int count) throws Exception {
//        List<Profile> profileList = new ArrayList<Profile>();
//
//        Statement statement = connection.createStatement();
//
//        statement.setQueryTimeout(30);
//        ResultSet rs = statement.executeQuery("select * from capture_profile order by create_time desc limit " + count);
//        while (rs.next()) {
//
//            File file = new File(ServerUtil.ResPath + rs.getString("profile_file_name"));
//
//            if(file.exists()){
//                Profile profile = new Profile(
//                        file,
//                        rs.getString("origin_file_name"),
//                        rs.getString("emotion"),
//                        rs.getInt("red_count"),
//                        rs.getInt("green_count"),
//                        rs.getInt("blue_count"),
//                        rs.getInt("pixel_count"),
//                        0//rs.getLong("create_time")
//                );
//
//                profileList.add(profile);
//            }
//
//        }
//
//        return profileList;
//    }
//
//    public static List<MosaicTemplate> getMosaicTemplateList() throws Exception {
//        List<MosaicTemplate> mosaicTemplateList = new ArrayList<MosaicTemplate>();
//
//        Statement statement = connection.createStatement();
//
//        statement.setQueryTimeout(30);
//        ResultSet rs = statement.executeQuery("select * from mosaic_template ");
//        while (rs.next()) {
//            MosaicTemplate mosaicTemplate = new MosaicTemplate();
//
//            mosaicTemplate.setX(rs.getInt("x"));
//            mosaicTemplate.setY(rs.getInt("y"));
//            mosaicTemplate.setWidth(rs.getInt("width"));
//            mosaicTemplate.setHeight(rs.getInt("height"));
//            mosaicTemplate.setRed_count(rs.getInt("red_count"));
//            mosaicTemplate.setGreen_count(rs.getInt("green_count"));
//            mosaicTemplate.setBlue_count(rs.getInt("blue_count"));
//            mosaicTemplate.setPixel_count(rs.getInt("pixel_count"));
//            mosaicTemplate.setCreate_time(rs.getLong("create_time"));
//
//            mosaicTemplateList.add(mosaicTemplate);
//        }
//
//        return mosaicTemplateList;
//    }
}
